/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events;

import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.GUIDStorage;

import org.json.simple.JSONObject;

/**
 * @author Massimo Canonaco
 */
public class TurnEvent implements GenericEvent {

	/** */
	private String oldPlayer;
	
	/** */
	private String newPlayer;
	
	/** */
	private boolean success;
	
	/** */
	static public final float GUID = GUIDStorage.TURN_EVENT;
	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getGUID()
	 */
	@Override
	public float getGUID() 
	{
		return GUID;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getName()
	 */
	@Override
	public String getName() 
	{
		return "turnEvent";
	}

	/**
	 * @return the oldPlayer
	 */
	public String getOldPlayer() {
		return oldPlayer;
	}

	/**
	 * @param oldPlayer the oldPlayer to set
	 */
	public void setOldPlayer(String oldPlayer) {
		this.oldPlayer = oldPlayer;
	}

	/**
	 * @return the newPlayer
	 */
	public String getNewPlayer() {
		return newPlayer;
	}

	/**
	 * @param newPlayer the newPlayer to set
	 */
	public void setNewPlayer(String newPlayer) {
		this.newPlayer = newPlayer;
	}

	/**
	 * @return the success
	 */
	public boolean isSuccess() 
	{
		return success;
	}

	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}

	@SuppressWarnings("unchecked")
	@Override
	public JSONObject getAsJSONObject() 
	{
		JSONObject object = new JSONObject();
		object.put(GLOBAL_GUID_KEY, GUID);
		object.put(NEW_KEY, newPlayer);
		object.put(OLD_KEY, oldPlayer);
		return object;
	}

	@Override
	public void setFromJSONOnbject(JSONObject object) 
	{
		newPlayer = (String) object.get(NEW_KEY);
		oldPlayer = (String) object.get(OLD_KEY);
	}

	static private final String NEW_KEY = "new";
	static private final String OLD_KEY = "old";
}
